<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>用 GPG 签名 GitHub的Commit | 秋澪冬安</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/assets/img/favicon.ico">
    <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
    <script>
            var _hmt = _hmt || [];
            (function () {
                let isLocal = window.location.hostname.includes("localhost");
                if(!isLocal){
                    var hm = document.createElement("script");
                    hm.src = "https://hm.baidu.com/hm.js?2b691637b166e447d963eab55f62c51f";
                    var s = document.getElementsByTagName("script")[0];
                    s.parentNode.insertBefore(hm, s);
                }
            })();
            </script>
    <meta name="description" content="一个分享技术、生活，整理笔记的个人博客">
    
    <link rel="preload" href="/assets/css/0.styles.c5fe4079.css" as="style"><link rel="preload" href="/assets/js/app.f1feaaa3.js" as="script"><link rel="preload" href="/assets/js/2.56bc1612.js" as="script"><link rel="preload" href="/assets/js/14.60692bb2.js" as="script"><link rel="prefetch" href="/assets/js/10.1e88977a.js"><link rel="prefetch" href="/assets/js/11.3149965c.js"><link rel="prefetch" href="/assets/js/12.a751fc6a.js"><link rel="prefetch" href="/assets/js/13.46a65100.js"><link rel="prefetch" href="/assets/js/15.74268a75.js"><link rel="prefetch" href="/assets/js/16.8a56e86b.js"><link rel="prefetch" href="/assets/js/17.cd4f0314.js"><link rel="prefetch" href="/assets/js/18.e4a559a0.js"><link rel="prefetch" href="/assets/js/19.2812e5f8.js"><link rel="prefetch" href="/assets/js/20.2a8bf95e.js"><link rel="prefetch" href="/assets/js/21.f0e889f9.js"><link rel="prefetch" href="/assets/js/22.be080c8c.js"><link rel="prefetch" href="/assets/js/23.f568ebff.js"><link rel="prefetch" href="/assets/js/24.c8946e24.js"><link rel="prefetch" href="/assets/js/25.13080108.js"><link rel="prefetch" href="/assets/js/26.4b7b31f3.js"><link rel="prefetch" href="/assets/js/27.d7d7f81f.js"><link rel="prefetch" href="/assets/js/28.faeb5048.js"><link rel="prefetch" href="/assets/js/29.1d40cd69.js"><link rel="prefetch" href="/assets/js/3.113aa5f9.js"><link rel="prefetch" href="/assets/js/30.f2d5999d.js"><link rel="prefetch" href="/assets/js/31.3919f392.js"><link rel="prefetch" href="/assets/js/32.d0cb9d84.js"><link rel="prefetch" href="/assets/js/33.67c73b82.js"><link rel="prefetch" href="/assets/js/34.7c153175.js"><link rel="prefetch" href="/assets/js/35.fb1bdca9.js"><link rel="prefetch" href="/assets/js/36.6b4bc7a1.js"><link rel="prefetch" href="/assets/js/4.a7fbcc6d.js"><link rel="prefetch" href="/assets/js/5.cbcdf0da.js"><link rel="prefetch" href="/assets/js/6.eedbdea5.js"><link rel="prefetch" href="/assets/js/7.7ac30410.js"><link rel="prefetch" href="/assets/js/8.444ebd43.js"><link rel="prefetch" href="/assets/js/9.ecf5a0cc.js">
    <link rel="stylesheet" href="/assets/css/0.styles.c5fe4079.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/assets/img/logo.png" alt="秋澪冬安" class="logo"> <span class="site-name can-hide">秋澪冬安</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">主页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="收藏" class="dropdown-title"><a href="/pages/87b1e9/" class="link-title">收藏</a> <span class="title" style="display:none;">收藏</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/87b1e9/" class="nav-link">网站</a></li><li class="dropdown-item"><!----> <a href="/pages/c47f0e/" class="nav-link">资源</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="个人建站" class="dropdown-title"><!----> <span class="title" style="display:;">个人建站</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://billsaul.gitee.io/genshinrecord" target="_blank" rel="noopener noreferrer" class="nav-link external">
  原神祈愿记录
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">关于</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="/assets/img/head portrait.webp"> <div class="blogger-info"><h3>秋澪冬安</h3> <span></span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">主页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="收藏" class="dropdown-title"><a href="/pages/87b1e9/" class="link-title">收藏</a> <span class="title" style="display:none;">收藏</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/pages/87b1e9/" class="nav-link">网站</a></li><li class="dropdown-item"><!----> <a href="/pages/c47f0e/" class="nav-link">资源</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="个人建站" class="dropdown-title"><!----> <span class="title" style="display:;">个人建站</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://billsaul.gitee.io/genshinrecord" target="_blank" rel="noopener noreferrer" class="nav-link external">
  原神祈愿记录
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div><div class="nav-item"><a href="/about/" class="nav-link">关于</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>瞎折腾</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/ef825e/" class="sidebar-link">Git配置ssh链接远程仓库</a></li><li><a href="/pages/6d1a67/" aria-current="page" class="active sidebar-link">用 GPG 签名 GitHub的Commit</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/pages/6d1a67/#_1-安装gpg" class="sidebar-link">1. 安装GPG</a></li><li class="sidebar-sub-header level2"><a href="/pages/6d1a67/#_2-生成gpg密钥" class="sidebar-link">2. 生成GPG密钥</a></li><li class="sidebar-sub-header level2"><a href="/pages/6d1a67/#_3-git设置" class="sidebar-link">3. Git设置</a></li><li class="sidebar-sub-header level2"><a href="/pages/6d1a67/#_4-获得公钥" class="sidebar-link">4. 获得公钥</a></li><li class="sidebar-sub-header level2"><a href="/pages/6d1a67/#_5-上传公钥到github" class="sidebar-link">5. 上传公钥到GitHub</a></li><li class="sidebar-sub-header level2"><a href="/pages/6d1a67/#_6-额外的命令补充" class="sidebar-link">6. 额外的命令补充</a></li></ul></li><li><a href="/pages/a79676/" class="sidebar-link">使用fluxion钓鱼获得wifi密码</a></li><li><a href="/pages/383198/" class="sidebar-link">bat批量删除指定以外的文件和文件夹</a></li><li><a href="/pages/1b1ed0/" class="sidebar-link">npm和yarn全局安装及缓存路径修改</a></li><li><a href="/pages/cc59bd/" class="sidebar-link">使用iPerf3测内网的网速</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>前端</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>树莓派4B</span> <span class="arrow right"></span></p> <!----></section></li><li><a href="/pages/1922ab/" class="sidebar-link">genshin-record项目文档</a></li><li><a href="/pages/4568fc/" class="sidebar-link">Windows配置Java环境变量</a></li><li><a href="/pages/c242c9/" class="sidebar-link">✨✨博客站点迁移提示✨✨</a></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-1baff76c><div class="articleInfo" data-v-1baff76c><ul class="breadcrumbs" data-v-1baff76c><li data-v-1baff76c><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-1baff76c></a></li> <li data-v-1baff76c><a href="/categories/?category=%E5%8D%9A%E5%AE%A2" title="分类" data-v-1baff76c>博客</a></li><li data-v-1baff76c><a href="/categories/?category=%E7%9E%8E%E6%8A%98%E8%85%BE" title="分类" data-v-1baff76c>瞎折腾</a></li></ul> <div class="info" data-v-1baff76c><!----> <div title="创建时间" class="date iconfont icon-riqi" data-v-1baff76c><a href="javascript:;" data-v-1baff76c>2020-11-06</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="">用 GPG 签名 GitHub的Commit<!----></h1> <!----> <div class="theme-vdoing-content content__default"><div class="custom-block tip"><p class="custom-block-title">摘自维基百科</p> <p>GNU Privacy Guard（GnuPG或GPG）是一个密码学软件，用于加密、签名通信内容及管理非对称密码学的密钥。GnuPG是自由软件，遵循IETF订定的OpenPGP技术标准设计，并与PGP保持兼容。</p></div> <div class="custom-block danger"><p class="custom-block-title">迁站提醒</p> <p>本博客已迁移至新域名<a href="https://www.meowpass.com" target="_blank" rel="noopener noreferrer">www.meowpass.com<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，本域名下的博客不再更新，但不会删除，欢迎访问新域名🎉🎉</p></div> <p>如果用 GitHub 客户端或者在 GitHub 网页上操作 git 都会在 commits 中留下 <code>Verified</code> 的标记，
这表示该 commit 是在 GitHub 上创建的，使用 GitHub 的 key 对这个提交进行了签名。
但 GitHub 客户端或者 GitHub 网页并不是签名 commit 的唯一方法，我们也可以通过 GnuPG (GPG) 来签名我们的 commit。<br></p><div class="pageimg" style="text-align:center;"><img src="" alt="图片"></div><p></p> <h2 id="_1-安装gpg"><a href="#_1-安装gpg" class="header-anchor">#</a> 1. 安装GPG</h2> <p><strong>Linux</strong> 一般都是自带GPG，可以直接使用<br>
如果没有可使用如下命令：</p> <div class="language- extra-class"><pre class="language-text"><code># Debian、Ubuntu 等
    apt-get install gnupg

# Redhat、Centos、Fedora 等
    yum install gnupg
</code></pre></div><p><strong>Windows</strong> 中MinGW带有GPG，而 Windows 版的 Git 基于 MinGW 的，所以直接使用git bash就行</p> <h2 id="_2-生成gpg密钥"><a href="#_2-生成gpg密钥" class="header-anchor">#</a> 2. 生成GPG密钥</h2> <p>git bash中使用命令：<code>gpg --gen-key</code></p> <div class="language- extra-class"><pre class="language-text"><code>$ gpg --gen-key
gpg (GnuPG) 2.2.15; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

注意：使用 “gpg --full-generate-key” 以获得一个功能完整的密钥产生对话框。

GnuPG 需要构建用户标识以辨认您的密钥。

真实姓名： name
电子邮件地址： name@qq.com

</code></pre></div><p>然后输入 <code>O</code> 确定</p> <div class="language- extra-class"><pre class="language-text"><code>更改姓名（N）、注释（C）、电子邮件地址（E）或确定（O）/退出（Q）？ o
</code></pre></div><p>然后会提示你</p> <div class="language- extra-class"><pre class="language-text"><code>我们需要生成大量的随机字节。在质数生成期间做些其他操作（敲打键盘、移动鼠标、读写硬盘之类的）将会是一个不错的主意；
这会让随机数发生器有更好的机会获得足够的熵
</code></pre></div><p>之后会弹出对话框让你输入密码
密钥生成完成之后，记下密钥 ID <code>43948FGB5418156F</code></p> <div class="language- extra-class"><pre class="language-text"><code>gpg: 密钥 43948FGB5418156F 被标记为绝对信任
gpg: 吊销证书已被存储为‘/home/name/.gnupg/openpgp-revocs.d/DC4E79EFEE5E224A20E9013A43948FGB5418156F.rev’
公钥和私钥已经生成并被签名。

pub   rsa2048 2020-11-6 [SC] [有效至：2022-11-6]
      DC4E79EFEE5E224A20E9013A43948FGB5418156F
uid                      name &lt;name@qq.com&gt;
sub   rsa2048 2020-11-6 [E] [有效至：2022-11-6]
</code></pre></div><h2 id="_3-git设置"><a href="#_3-git设置" class="header-anchor">#</a> 3. Git设置</h2> <div class="custom-block tip"><p class="custom-block-title">提示</p> <p>想全局设置，在命令中加上 <code>--global</code> 参数</p></div> <p>让 Git 使用我们的密钥来对 commit 进行签名</p> <div class="language- extra-class"><pre class="language-text"><code>git config user.signingkey &lt;密钥ID&gt;
</code></pre></div><p>设置 Git 使用该密钥加密 commit</p> <div class="language- extra-class"><pre class="language-text"><code>git config commit.gpgsign true
</code></pre></div><p>顺便设置 Git 全局使用该密钥加密 tag</p> <div class="language- extra-class"><pre class="language-text"><code>git config tag.forcesignannotated true
</code></pre></div><h2 id="_4-获得公钥"><a href="#_4-获得公钥" class="header-anchor">#</a> 4. 获得公钥</h2> <p>公钥文件是以二进制的形式储存的，我们使用 <code>--armor</code> 参数将它转换成 ASCII 码的形式输出</p> <div class="language- extra-class"><pre class="language-text"><code>gpg --armor --export &lt;密钥ID&gt;
</code></pre></div><p>复制输出的公钥</p> <h2 id="_5-上传公钥到github"><a href="#_5-上传公钥到github" class="header-anchor">#</a> 5. 上传公钥到GitHub</h2> <p>在 GitHub 的设置页面的 SSH and GPG keys，点击 New GPG key添加就行<br>
以后你在这台计算机推送到 GitHub 的 commit 就都带有 GPG 签名了
</p><div class="pageimg" style="text-align:center;"><img src="" alt="图片"></div><p></p> <h2 id="_6-额外的命令补充"><a href="#_6-额外的命令补充" class="header-anchor">#</a> 6. 额外的命令补充</h2> <ul><li>列出密钥：<code>gpg --list-keys</code></li> <li>删除私钥：<code>gpg --delete-secret-keys &lt;密钥ID&gt;</code></li> <li>删除公钥：<code>gpg --delete-keys &lt;密钥ID&gt;</code></li></ul></div></div> <!----> <div class="page-edit"><!----> <div class="tags"><a href="/tags/?tag=Git" title="标签">#Git</a><a href="/tags/?tag=GPG" title="标签">#GPG</a></div> <div class="last-updated"><span class="prefix">上次编辑:</span> <span class="time">2021/03/09, 00:11:16</span></div></div> <div class="page-nav-wapper"><!----> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/ef825e/" class="prev">Git配置ssh链接远程仓库</a></span> <span class="next"><a href="/pages/a79676/">使用fluxion钓鱼获得wifi密码</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/c242c9/"><div>
            ✨✨博客站点迁移提示✨✨
            <!----></div></a> <span class="date">04-24</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/d38aff/"><div>
            VSCode生成头部注释
            <!----></div></a> <span class="date">01-03</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/f002e9/"><div>
            VSCode配置文件配置项
            <!----></div></a> <span class="date">12-22</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="https://github.com/BillSaul" title="GitHub" target="_blank" class="iconfont icon-github-fill-round"></a><a href="mailto:billsaul@github.email.cn" title="发邮件" target="_blank" class="iconfont icon-email"></a><a href="https://gitee.com/billsaul" title="Gitee" target="_blank" class="iconfont icon-gitee-fill-round"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2020-2022
    <span>秋澪冬安 | Gitee BillSaul</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.f1feaaa3.js" defer></script><script src="/assets/js/2.56bc1612.js" defer></script><script src="/assets/js/14.60692bb2.js" defer></script>
  </body>
</html>
